package com.yuntongxun.ecdemo.voicechat.ui.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuntongxun.ecdemo.R;

import java.io.IOException;
import java.util.List;

/**
 * 国籍选择
 * @author li_zhuonan@163.com
 * @version 1.0
 * @since 2016/11/16
 */

public class FlagAdapter extends BaseAdapter {

    private List<Bitmap> imgs;
    private String[] titles;
    Context mContext;

    public FlagAdapter(Context mContext,List<Bitmap> imgs, String[] titles){
        this.mContext=mContext;
        this.imgs=imgs;
        this.titles=titles;
    }

    @Override
    public int getCount() {
        if (imgs!=null){
            return imgs.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return imgs.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_flag_item, null);
            holder = new ViewHolder();
            holder.tagTv=(TextView)convertView.findViewById(R.id.flag_item_tv);
            holder.flagImg=(ImageView)convertView.findViewById(R.id.flag_item_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tagTv.setText(titles[i]);
        holder.flagImg.setImageBitmap(imgs.get(i));

        return convertView;
    }

    private class ViewHolder {
        TextView tagTv;
        ImageView flagImg;
    }

}
